package com.example.day07_zhongji.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.day07_zhongji.R;
import com.example.day07_zhongji.bean.ListBean;

import java.util.List;

public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ViewHolder> {
    private Context context;
    private List<ListBean.DataBean.DatasBean> data;


    public ListAdapter(Context context, List<ListBean.DataBean.DatasBean> data) {
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public ListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ListAdapter.ViewHolder holder, int position) {
        ListBean.DataBean.DatasBean datasBean = data.get(position);
        holder.title.setText(datasBean.getChapterName());
        holder.text.setText(datasBean.getAuthor());
        holder.dsec.setText(datasBean.getDesc());
        holder.sj.setText(datasBean.getNiceDate());
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView text;
        TextView title;
        TextView dsec;
        TextView sj;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            text=itemView.findViewById(R.id.list_text);
            title=itemView.findViewById(R.id.list_title);
            dsec=itemView.findViewById(R.id.list_desc);
            sj=itemView.findViewById(R.id.list_sj);
        }
    }
}
